package com.hsmw.api.controller.forman;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsmw.api.service.HsmwLeasingCompanyRuleService;
import com.htn.common.core.base.DataResponse;
import com.htn.common.core.constant.CommonConstants;
import com.hsmw.domain.HsmwLeasingCompanyRule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.hsmw.common.base.BaseController;

import java.util.List;

/**
 * <p>
 *  归属公司规则信息
 * </p>
 *
 * @author 许昌
 * @since 2021-08-05
 */
@RestController
@Api(tags = "")
@RequestMapping("/api/rule")
public class HsmwLeasingCompanyRuleController extends BaseController<HsmwLeasingCompanyRuleService, HsmwLeasingCompanyRule> {


    @Autowired
    private HsmwLeasingCompanyRuleService hsmwLeasingCompanyRuleService;

    @ApiOperation(value = "list", notes = "list", produces = "application/json")
    @ApiImplicitParam(value = "归属公司id", name = "id", dataType = "String")
    @PostMapping("list")
    public DataResponse list (String id){

        List<HsmwLeasingCompanyRule> hsmwLeasingCompanyRules = hsmwLeasingCompanyRuleService.list(new LambdaQueryWrapper<HsmwLeasingCompanyRule>().eq(HsmwLeasingCompanyRule::getLeasingCompanyId,id));

        return new DataResponse(CommonConstants.ResponseStatus.SUCCESS,hsmwLeasingCompanyRules);

    }



    @ApiOperation(value = "新增或者修改", notes = "新增或者修改", produces = "application/json")
    @PostMapping("saveOrUpdateRule")
    public DataResponse saveOrUpdateRule(@RequestBody HsmwLeasingCompanyRule hsmwLeasingCompanyRule){
        if(hsmwLeasingCompanyRule == null){
            return new DataResponse(CommonConstants.ResponseStatus.FAIL,"传递参数为空");
        }
        boolean suc = hsmwLeasingCompanyRuleService.saveOrUpdateRule(hsmwLeasingCompanyRule);
        if(suc){
            return new DataResponse(CommonConstants.ResponseStatus.SUCCESS,suc);
        }
        return new DataResponse(CommonConstants.ResponseStatus.FAIL,suc);
    }



}

